import 'dart:math';

import 'package:flutter/material.dart';

/// Diagonal clipper with rounded borders
class RoundedDiagonalPathClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    final width = size.width;
    final height = size.height;
    double leftTopRadius = 28;
    double rightTopRadius = 22;
    double leftBottomRadius = 32;
    double rightBottomRadius = 32;
    final leftTopRect =
        Rect.fromLTRB(0, 7, leftTopRadius * 2, leftTopRadius * 2);
    final leftBottomRect = Rect.fromLTRB(
        0, height - leftBottomRadius * 2, leftBottomRadius * 2, height);
    final rightTopRect =
        Rect.fromLTRB(width - 2 * rightTopRadius, 0, width, rightTopRadius * 2);
    final rightBottomRect = Rect.fromLTRB(width - 2 * rightBottomRadius,
        height - rightBottomRadius * 2, width, height);
    final path = Path();
    //左上角 圆弧
    path.arcTo(leftTopRect, 180 / 180 * pi, 90 / 180 * pi, false);
    //右上角圆弧
    path.lineTo(width - rightTopRadius, 0);
    path.arcTo(rightTopRect, 270 / 180 * pi, 90 / 180 * pi, false);
    //右下角
    path.lineTo(width, height - rightBottomRadius);
    path.arcTo(rightBottomRect, 0, 90 / 180 * pi, false);
    //左下角
    path.lineTo(leftBottomRadius, height);
    path.arcTo(leftBottomRect, 90 / 180 * pi, 90 / 180 * pi, false);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
  }
}
